<?php

declare (strict_types=1);

namespace App\Model;

use Hyperf\Database\Model\Relations\HasOne;

/**
 * @property int $id
 * @property int $order_id
 * @property int $pay_order_id
 * @property int $sku_id
 * @property string $sku_name
 * @property int $product_id
 * @property string $product_name
 * @property string $single_price
 * @property int $quantity
 * @property string $subtotal
 * @property int $industry_id
 * @property string $industry_name
 * @property int $min_quantity
 * @property int $delivery_id
 * @property string $limit_quantity
 * @property int $dc_id
 * @property string $dc_name
 */
class FlyOrderProduct extends Model
{
    public $timestamps = false;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_order_product';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'order_id' => 'integer', 'pay_order_id' => 'integer', 'sku_id' => 'integer', 'product_id' => 'integer', 'quantity' => 'integer', 'industry_id' => 'integer', 'min_quantity' => 'integer', 'delivery_id' => 'integer', 'dc_id' => 'integer'];

    /**
     * 关联模型
     * @return HasOne
     */
    public function with_product()
    {
        return $this->hasOne(Product::class, 'id', 'product_id')
            ->with(['sku_list', 'main_pic', 'detail_pic', 'file_info', 'link_channel', 'industry_info', 'spec_key',
                'shop_info', 'landmark_info', 'specialty_info', 'audit_info', 'certify_info', 'shop_min_sku'])
            ->where('is_illegal', '=', 0)
            ->where('is_show', '=', 1)
            ->where('check_status', 1);
    }

    /**
     * 转换支付时间
     * @param int $time
     * @return string
     */
    public function getPaidTimeAttribute(int $time): string
    {
        return date('Y-m-d H:i:s', $time);
    }
}